/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package drt;

import evaluation.Edge;
import evaluation.Graph;
import evaluation.Vertex;
import java.util.LinkedHashSet;
import java.util.Map;
import logic.Type;

/**
 *
 * @author phong
 */
public class SDRSDiscourseRelationCondition extends SDRSCondition{
    
    DRSReferent first, second;
    String symbol;
    
    public SDRSDiscourseRelationCondition(String symbol, DRSReferent first, DRSReferent second) {
        this.first = first;
        this.second = second;
        this.symbol = symbol;
    }
    
    public DRSReferent getFirst() {
        return this.first;
    }
    
    public DRSReferent getSecond() {
        return this.second;
    }
    
    public String getSymbol() {
        return this.symbol;
    }
    
    @Override
    public Type getType() {
        return Type.TRUTH_TYPE;
    }
 
    @Override
    public SDRSDiscourseRelationCondition simplify() {
        return this;
    }
    
    @Override
    public SDRSDiscourseRelationCondition replace(DrtVariable var, DrtExpression exp) {
        return this;
    }
    
    @Override
    public void getAllVariables(LinkedHashSet<DrtVariable> vars) {
        vars.add(first);
        vars.add(second);
    }
    
    @Override
    public void getRefs(LinkedHashSet<DRSReferent> refs) {
        this.first.getRefs(refs);
        this.second.getRefs(refs);
    }

    @Override
    public Graph toGraph() {
        Graph g = new Graph();
        Vertex v1 = new Vertex(this.first.getName(), Vertex.TYPE_REF);
        Vertex v2 = new Vertex(this.first.getName(), Vertex.TYPE_REF);
        Vertex f = new Vertex(this.symbol, Vertex.TYPE_PRED);
        g.addEdge(new Edge("1", v1, f));
        g.addEdge(new Edge("2", v2, f));
        g.addMarks(f);
        return g;
    }
    
    @Override
    public SDRSDiscourseRelationCondition getTemplate(Map<String,String> map) {
        String template = map.get(this.symbol);
        if (template == null) {
            template = TemplateNaming.getUniqueName();
            map.put(this.symbol, template);
        }
        return new SDRSDiscourseRelationCondition(template, first, second);
    }
    
    @Override
    public String toString() {
        return this.symbol + "(" + this.first + "," + this.second + ")";
    }
}
